Repository navigation
fix(agent-hooks): stop test runs and secondary profiles deleting the user's agent hooks (STA-5679) - #16980
Conversation
…ed hooks (STA-5679) Startup reconciliation removed the managed agent hooks whenever THIS profile had the agent-status-hooks off switch set. The hook files it removes are user-global (~/.claude/settings.json, ~/.cursor/hooks.json), so a second Orca profile with the switch off deleted the hooks every other running instance depends on. Cursor is the only agent with no title-derived status fallback: its native title is deliberately parsed as status-less, so a hookless Cursor pane is floored at 'idle' rather than showing a spinner. A global hook wipe therefore surfaces as "Cursor loading status missing from the sidebar" while Claude and Codex still paint status from their own titles, which is why this reads as a Cursor-only bug. Codex is unaffected either way because its hooks live in an Orca-owned runtime home. Honoring the off switch only requires skipping the install; removal stays on the explicit Settings toggle, which is the user-initiated path that should own it. Regression from #2778, which restored the destructive startup branch.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change adds startup action resolution and per-agent startup installation checks. Startup reconciliation installs managed hooks only when global settings enable them and the agent is not disabled. Disabled settings now skip reconciliation instead of removing user-global managed hook files. Explicit Settings toggles still remove managed hooks. Tests cover startup states, disabled agents, and the explicit removal path. Merge Risk: ⚪ Minimal · up to The change prevents test runs and disabled profiles from deleting shared agent hooks while preserving explicit user-requested removal. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the two deletion paths, the implementation scope, and verification results. However, it does not follow the repository template and omits or leaves incomplete several required sections, including ELI5, What Changed, Why, Linked Issue with an issue number, Visual Proof or N/A, testing checkboxes and platform details, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Restructure the description using the repository template. Add the required section headings and content, provide the linked issue in the
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/agent-hooks/managed-agent-hook-controls.ts (1)
46-50: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReduce the repeated startup rationale to concise comments.
src/main/agent-hooks/managed-agent-hook-controls.ts#L46-L50: replace this with one policy comment.src/main/agent-hooks/managed-agent-hook-controls.test.ts#L284-L285: remove or reduce this test explanation to one line.src/main/agent-hooks/managed-agent-hook-controls.test.ts#L296-L297: remove or reduce this test explanation to one line.src/main/index.ts#L3100-L3102: remove the duplicate rationale or use one short policy comment.As per coding guidelines,
**/*.{ts,tsx,js,jsx}requires concise comments, one line if possible.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e3e106d8-205e-4bfb-837f-077fcff8e6ef
📒 Files selected for processing (3)
src/main/agent-hooks/managed-agent-hook-controls.test.tssrc/main/agent-hooks/managed-agent-hook-controls.tssrc/main/index.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
… agent hooks runtime-client-deferral.test.ts runs the REAL `main()` and feeds it `agent hooks off`. It mocks only ./runtime/environments and ./runtime-client, so the production handler ran end to end: updateEnabledOnDisk() wrote its state file and applyAgentStatusHooksEnabled(false) called removeManagedAgentHooks() against the developer's OWN ~/.claude/settings.json and ~/.cursor/hooks.json. A green test run therefore deleted every Orca-managed hook on the machine. Agent status then stopped reporting until the next Orca restart reinstalled them — silently, because the hook POSTs still return 204 and Cursor has no title-derived status fallback at all. The byte-for-byte equivalence twin already refuses these exact tokens, commented "MUTATING — writes outside ORCA_USER_DATA_PATH (`agent hooks off` parks the real ~/.claude hooks)". The vitest twin never got that guard. Stub the hook-controls module rather than dropping the row: `agent hooks off` is the only case in the table that reads ctx.client, so it carries the null-vs-undefined coverage the other four cannot. All 23 tests still pass, and a sandboxed HOME now keeps its hooks (5 -> 5) where it previously lost them (5 -> 0).
Review status: PASS / CLEANCompleted the requested review loop with same-model, xhigh-reasoning subagents, including The loop found and pushed two meaningful, in-scope improvements:
Post-fix adversarial review and the final readiness pass found no remaining P0/P1/P2 correctness, lifecycle, regression, cross-platform, security, or performance issues. The implementation is aligned with established managed-integration precedent: automatic startup may reconcile/install shared user-global integration state, but profile-local startup preferences must not destructively remove it; destructive cleanup remains tied to explicit user action. Verification completed:
Residual note: no Electron/mobile UI validation was run because this PR changes non-visual main-process startup and test safety paths; the rendered UI is unchanged. The branch is clean, pushed, and the PR currently reports a clean merge state. |
…user's agent hooks (STA-5679) (stablyai#16980) * fix(agent-hooks): stop startup from deleting another instance's managed hooks (STA-5679) Startup reconciliation removed the managed agent hooks whenever THIS profile had the agent-status-hooks off switch set. The hook files it removes are user-global (~/.claude/settings.json, ~/.cursor/hooks.json), so a second Orca profile with the switch off deleted the hooks every other running instance depends on. Cursor is the only agent with no title-derived status fallback: its native title is deliberately parsed as status-less, so a hookless Cursor pane is floored at 'idle' rather than showing a spinner. A global hook wipe therefore surfaces as "Cursor loading status missing from the sidebar" while Claude and Codex still paint status from their own titles, which is why this reads as a Cursor-only bug. Codex is unaffected either way because its hooks live in an Orca-owned runtime home. Honoring the off switch only requires skipping the install; removal stays on the explicit Settings toggle, which is the user-initiated path that should own it. Regression from stablyai#2778, which restored the destructive startup branch. * fix(cli-tests): stop the deferral suite deleting the developer's real agent hooks runtime-client-deferral.test.ts runs the REAL `main()` and feeds it `agent hooks off`. It mocks only ./runtime/environments and ./runtime-client, so the production handler ran end to end: updateEnabledOnDisk() wrote its state file and applyAgentStatusHooksEnabled(false) called removeManagedAgentHooks() against the developer's OWN ~/.claude/settings.json and ~/.cursor/hooks.json. A green test run therefore deleted every Orca-managed hook on the machine. Agent status then stopped reporting until the next Orca restart reinstalled them — silently, because the hook POSTs still return 204 and Cursor has no title-derived status fallback at all. The byte-for-byte equivalence twin already refuses these exact tokens, commented "MUTATING — writes outside ORCA_USER_DATA_PATH (`agent hooks off` parks the real ~/.claude hooks)". The vitest twin never got that guard. Stub the hook-controls module rather than dropping the row: `agent hooks off` is the only case in the table that reads ctx.client, so it carries the null-vs-undefined coverage the other four cannot. All 23 tests still pass, and a sandboxed HOME now keeps its hooks (5 -> 5) where it previously lost them (5 -> 0). * fix(cli-tests): ratchet agent hook deferral safety * fix(agent-hooks): keep startup reconciliation install-only (cherry picked from commit 2c86d2a)
…user's agent hooks (STA-5679) (stablyai#16980) * fix(agent-hooks): stop startup from deleting another instance's managed hooks (STA-5679) Startup reconciliation removed the managed agent hooks whenever THIS profile had the agent-status-hooks off switch set. The hook files it removes are user-global (~/.claude/settings.json, ~/.cursor/hooks.json), so a second Orca profile with the switch off deleted the hooks every other running instance depends on. Cursor is the only agent with no title-derived status fallback: its native title is deliberately parsed as status-less, so a hookless Cursor pane is floored at 'idle' rather than showing a spinner. A global hook wipe therefore surfaces as "Cursor loading status missing from the sidebar" while Claude and Codex still paint status from their own titles, which is why this reads as a Cursor-only bug. Codex is unaffected either way because its hooks live in an Orca-owned runtime home. Honoring the off switch only requires skipping the install; removal stays on the explicit Settings toggle, which is the user-initiated path that should own it. Regression from stablyai#2778, which restored the destructive startup branch. * fix(cli-tests): stop the deferral suite deleting the developer's real agent hooks runtime-client-deferral.test.ts runs the REAL `main()` and feeds it `agent hooks off`. It mocks only ./runtime/environments and ./runtime-client, so the production handler ran end to end: updateEnabledOnDisk() wrote its state file and applyAgentStatusHooksEnabled(false) called removeManagedAgentHooks() against the developer's OWN ~/.claude/settings.json and ~/.cursor/hooks.json. A green test run therefore deleted every Orca-managed hook on the machine. Agent status then stopped reporting until the next Orca restart reinstalled them — silently, because the hook POSTs still return 204 and Cursor has no title-derived status fallback at all. The byte-for-byte equivalence twin already refuses these exact tokens, commented "MUTATING — writes outside ORCA_USER_DATA_PATH (`agent hooks off` parks the real ~/.claude hooks)". The vitest twin never got that guard. Stub the hook-controls module rather than dropping the row: `agent hooks off` is the only case in the table that reads ctx.client, so it carries the null-vs-undefined coverage the other four cannot. All 23 tests still pass, and a sandboxed HOME now keeps its hooks (5 -> 5) where it previously lost them (5 -> 0). * fix(cli-tests): ratchet agent hook deferral safety * fix(agent-hooks): keep startup reconciliation install-only
Two ways Orca deletes the user's own agent hooks. Both empty the user-global files
~/.claude/settings.jsonand~/.cursor/hooks.json, and both are silent — the hook POSTs keep returning204afterwards.1. A green test run deletes the developer's real hooks (the one that bites)
src/cli/runtime-client-deferral.test.ts:113feeds['agent','hooks','off']to the realmain(). It mocks only./runtime/environmentsand./runtime-client, so the production handler runs end to end —agent-hooks.ts:197writes its state file, then:202callsapplyAgentStatusHooksEnabled(false)→removeManagedAgentHooks()→ the developer's own~/.claudeand~/.cursor.Measured with a sandboxed
HOME:The repo already knew. The byte-for-byte equivalence twin refuses these exact tokens:
The vitest twin never got that guard. Live since #10919 (2026-07-27).
Stubbed rather than dropped:
agent hooks offis the only row in that table that readsctx.client, so it carries the null-vs-undefined coverage the other four cannot. All 23 tests still pass.2. Startup removal is per-profile but user-global
src/main/index.tsremoved the hooks whenever this profile had the off switch set. The decision reads one profile's settings; the files are shared by every instance — so a secondary profile with the switch off deletes the primary's hooks.shouldInstallManagedHooks()returnstrueunconditionally, so dev builds and test rigs do this to the real config too.Honoring the off switch only needs the install skipped; removal stays on the explicit Settings toggle, which is the user-initiated path that should own it.
Verified end to end in Electron with a sandboxed
HOMEand a profile whose ownagentStatusHooksEnabledisfalse:Only the
hookskey is affected either way — other settings survive.Why this shows up as "Cursor status missing"
Cursor is the only agent with no title-derived status fallback: its native title is deliberately parsed as status-less (
agent-title-status.ts:175-177), never reaches the tracker (terminal-output-side-effects.ts:167-180), and STA-2472 floors the row at'idle'(worktree-title-derived-agent-rows.ts:152-154). So a hook wipe makes Cursor go completely silent while Claude and Codex still paint status from their own titles. Codex is unaffected regardless — its hooks live in an Orca-owned runtime home.Tests
Three in
managed-agent-hook-controls.test.ts, verified failing-first: restoring the pre-fix behavior fails withexpected 'remove' to be 'skip'. A third test asserts removers still fire on the explicit toggle, anchoring the first against being a vacuous constant.Scope
Deliberately not included: the Settings toggle still removes user-globally by design — a user with two profiles who flips it in one loses hooks in both. That is a product decision, not a bug, and is left alone here.